<template>
	<view class="hwq-content">
		<navBar title="险情列表"></navBar>
		<searchCom class="search-input" v-model="searchText"></searchCom>
		<scroll-view scroll-y="true" class="hwq-scroll-box hwq-is-search">
			<u-swipe-action>
				<u-swipe-action-item :options="options" v-for="item in list" :key="item.id" :show="true" :name="item.id"
					@click="swipeClick">
					<view class="swipe-action">
						<view class="top-box">
							<view class="name">{{item.bizProjectName||''}}</view>
							<view class="point">{{item.sectionName||""}}/{{item.siteName||''}}</view>
						</view>
						<view class="bottom-box">
							<view class="department">{{item.orgName||""}}</view>
							<view class="time">{{item.startTime2||''}}</view>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getListByNameByLike
	} from "@/api/emergency/emergencyDispatch.js"
	import searchCom from "@/components/searchCom.vue"
	export default {
		data() {
			return {
				options: [{
					text: '编辑',
					style: {
						backgroundColor: '#2F80ED ',
						color: "#fff"
					}
				}, {
					text: '分享',
					style: {
						backgroundColor: '#FFA000',
						color: "#fff"
					}
				}],
				list: [],
				searchText: undefined
			}
		},
		components: {
			searchCom
		},
		created() {
			this.getData()
		},
		methods: {
			swipeClick({
				name,
				index
			}) {
				if (index === 0) {
					//编辑
					let item = this.list.find(item => item.id === name)
					uni.navigateTo({
						url: '/subpackage-emergency/pages/reportEmergency',
						events: {
							getList: () => {
								this.getData()
							}
						},
						success: res => {
							res.eventChannel.emit('setData', {
								data: item
							})
						},
					});
				} else {
					let projectId = uni.getStorageSync("isOwner") || ""
					let item = this.list.find(item => item.id === name)
					let value = this.$config.SHARE_URL +
						`?token=${uni.getStorageSync("token")}&id=${item.id}&projectId=${projectId}&page=updateDanger`
					uni.setClipboardData({
						data: value, //要被复制的内容
						success: () => { //复制成功的回调函数
							uni.showToast({ //提示
								title: '复制成功'
							})
						}
					});
				}
				console.log("swipeClickswipeClick", name, index)
			},
			async getData() {
				let _query = {
					currPage: 1,
					pageSize: 10000,
					params: {
						orgId: "", // 组织id
						state: 0
					}
				}
				let res = await getListByNameByLike(_query)
				res.result.list.forEach(item => {
					item.startTime2 = this.getDate(item.startTime)
					switch (item.state) {
						case 0:
							item.stateText = '处置中'
							break
						case 1:
							item.stateText = '归档'
							break
					}
				})
				this.list = res.result.list
			},
			// 转换日期 获得年月日
			getDate(date) {
				if (!date) return ''
				var d = new Date(date)
				const y = d.getFullYear()
				let m = d.getMonth() + 1
				let did = d.getDate()
				let h = d.getHours()
				if (m < 10) {
					m = '0' + m
				}
				if (did < 10) {
					did = '0' + did
				}
				if (h < 10) {
					h = '0' + h
				}
				let minute = d.getMinutes()
				if (minute < 10) {
					minute = '0' + minute
				}
				let second = d.getSeconds()
				if (second < 10) {
					second = '0' + second
				}
				return y + '-' + m + '-' + did + ' ' + h + ':' + minute + ':' + second
			},
		}
	}
</script>

<style lang="scss" scoped>
	.swipe-action {
		padding-top: 10rpx;

		.top-box {
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #22204E;
			line-height: 70rpx;
			display: flex;
			justify-content: space-between;
			padding-right: 20rpx;

			.name {
				max-width: 60%;
				overflow: hidden; //超出的文本隐藏
				text-overflow: ellipsis; //用省略号显示
				white-space: nowrap; //不换行
			}

			.point {
				color: #445469;
			}
		}

		.bottom-box {
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #6A819E;
			line-height: 36rpx;
			display: flex;
			justify-content: space-between;
			border-bottom: 2rpx solid #E2E5ED;
			padding-right: 20rpx;

			.department {
				padding-bottom: 32rpx;
				width: 60%;
				overflow: hidden; //超出的文本隐藏
				text-overflow: ellipsis; //用省略号显示
				white-space: nowrap; //不换行
			}

			.time {
				color: #6A819E;
				float: right;
			}
		}
	}
</style>
